//
//  LCRankingViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/24.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCRankingViewController.h"


#import "LCRankingListViewController.h"

@interface LCRankingViewController ()

@property (weak, nonatomic) IBOutlet LCBaseScrollView *baseScrollView;

@property (weak, nonatomic) IBOutlet UIView *rankBV;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rankBgViewH;

@property (nonatomic, assign) BOOL canScroll;

@end

@implementation LCRankingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)configUI {
    self.canScroll = YES;
    
    [LCNotiCenter addObserver:self selector:@selector(rankListControllerLeaveTop:) name:LCRankPageControllerLeaveTopNoti object:nil];
    
    self.baseScrollView.width = ScreenW;
    self.rankBgViewH.constant = ScreenH-NavgationHeight-TabRelativeBottomH-14;
    self.rankBV.width = ScreenW-34;
    
    LCRankingListViewController * listVC = [LCRankingListViewController xx_instantiateFromStoryboardNamed:@"MineTool"];
    listVC.view.frame = CGRectMake(0, 0, ScreenW-34, CGRectGetHeight(self.rankBV.frame));
    [self.rankBV addSubview:listVC.view];
    [self addChildViewController:listVC];
}

- (void)rankListControllerLeaveTop:(NSNotification *)notif {
    self.canScroll = [notif.object boolValue];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat maxOffsetY = 150;
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY >= maxOffsetY) {
        _canScroll = NO;
        scrollView.contentOffset = CGPointMake(0, maxOffsetY);
        [[NSNotificationCenter defaultCenter] postNotificationName:LCRankListControllerGoTopNoti object:@(YES)];
    } else {
        if (!_canScroll) {
            scrollView.contentOffset = CGPointMake(0, maxOffsetY);
        }
    }
}




@end
